package com.example.rbacmanage.service.impl;

import com.example.rbacmanage.entity.GenFieldConfig;
import com.example.rbacmanage.exception.MyException;
import com.example.rbacmanage.mapper.GenFieldConfigMapper;
import com.example.rbacmanage.service.GenFieldConfigService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class GenFieldConfigServiceImpl implements GenFieldConfigService {
    @Autowired
    private GenFieldConfigMapper genFieldConfigMapper;
    @Override
    public void save(GenFieldConfig genFieldConfig) {
        genFieldConfig.setCreateTime(new Date());
        genFieldConfigMapper.insert(genFieldConfig);
    }

    @Override
    public void remove(Long[] ids) {
        for (Long id : ids) {
            genFieldConfigMapper.del(id);
        }
    }

    @Override
    public void update(GenFieldConfig genFieldConfig) {
        genFieldConfigMapper.update(genFieldConfig);
    }

    @Override
    public List<GenFieldConfig> getAll(GenFieldConfig genFieldConfig) {
        return genFieldConfigMapper.list(genFieldConfig);
    }

    @Override
    public PageInfo<GenFieldConfig> getPage(GenFieldConfig genFieldConfig) {
        PageHelper.startPage(genFieldConfig.getPage(), genFieldConfig.getLimit());
        return new PageInfo<>(getAll(genFieldConfig));
    }

    @Override
    public GenFieldConfig getById(Long id) {
        return genFieldConfigMapper.queryOneById(id);
    }

    @Override
    public Integer getCount(GenFieldConfig genFieldConfig) {
        return genFieldConfigMapper.count(genFieldConfig);
    }

    @Override
    public void checkRepeat(GenFieldConfig genFieldConfig) throws MyException {

    }

    @Override
    public void removeByConfigId(Long configId) {
        genFieldConfigMapper.removeByConfigId(configId);
    }
}
